package com.cowcowit.springcloud.controller;

import cn.hutool.core.date.DateUtil;
import com.cowcowit.springcloud.apis.PayFeignApi;
import com.cowcowit.springcloud.entity.PayDTO;
import com.cowcowit.springcloud.result.ResultData;
import com.cowcowit.springcloud.result.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
public class OrderController {

    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping(value = "/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {

        ResultData resultData = payFeignApi.addPay(payDTO);
        return resultData;
    }

    @GetMapping(value = "/feign/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id) {
        ResultData resultData = null;
        try {
            System.out.println("调用开始-----: " + DateUtil.now());
            resultData = payFeignApi.getPayInfo(id);
            System.out.println("调用结束-----: " + DateUtil.now());
        } catch (Exception e) {
            e.printStackTrace();

            ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        return resultData;
    }

    @GetMapping(value = "/feign/pay/mylb")
    public String mylb() {
        return payFeignApi.mylb();
    }

}